//
//  PerfectPersonVC.m
//  leyitui
//
//  Created by 王大江 on 17/9/22.
//  Copyright © 2017年 xinleyi. All rights reserved.
//

#import "PerfectPersonVC.h"
#import "PGTabBarController.h"
#import "NSString+Check.h"

@interface PerfectPersonVC ()
@property (weak, nonatomic) IBOutlet UITextField *nameTF;
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;

@property (weak, nonatomic) IBOutlet UIButton *sexManBtn;
@property (weak, nonatomic) IBOutlet UIButton *sexWomanBtn;


@property (weak, nonatomic) UIButton *currentSelectedBtn;


@end

@implementation PerfectPersonVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.phoneTF.keyboardType = UIKeyboardTypeNumberPad;
    
    
}

- (IBAction)sexManBtnClick:(id)sender {
    UIButton *btn = (UIButton *)sender;
    if (btn.selected) {
        return ;
    }
    btn.selected = true;
    self.currentSelectedBtn = btn;
    self.sexWomanBtn.selected = false;
    
    
}

- (IBAction)sexWomenBtnClick:(id)sender {
    UIButton *btn = (UIButton *)sender;
    if (btn.selected) {
        return ;
    }
    btn.selected = true;
    self.currentSelectedBtn = btn;
    self.sexManBtn.selected = false;
    
    
}

- (IBAction)commitBtnClick:(id)sender {
    if (![self.phoneTF.text checkPhoneNumInput]) {
        [MBProgressHUD showError:@"请输入正确的手机号"];
        return;
    }
    
    NSMutableDictionary *para = [[NSMutableDictionary alloc] init];
    para[@"realname"] = self.nameTF.text;
    if (self.currentSelectedBtn == self.sexManBtn) {
        para[@"sex"] = @"男";
    } else {
        para[@"sex"] = @"女";
    }
    para[@"mobile"] = self.phoneTF.text;
    
    [XYNetworking POST:@"api/update" baseURL:LYT_BASE_URL params:para success:^(NSURLSessionDataTask *task, id responseObject) {
        NSDictionary *dict = (NSDictionary*)responseObject;
        if ([dict[@"code"] intValue] == 0) {
            [MBProgressHUD showSuccess:@"保存成功!"];
            [self.parentViewController.navigationController popViewControllerAnimated:YES];
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        [MBProgressHUD showError:@"请检查网络"];
    }];
    
    
}






@end
